﻿Ext.namespace("ext.net.comjs");

ext.net.comjs.onPageSizeChange = function (combo) {
    var store = combo.up("gridpanel").getStore();
    store.pageSize = parseInt(combo.getValue(), 10);
    store.loadPage(1);
};

ext.net.comjs.onGridChange = function (store, operation) {
    var result = Ext.decode(operation.response.responseText);
    var success = result.result.Success;
    var msg = result.result.Msg;
    if (success) {
        store.reload();
    }
    else {
        Ext.Msg.show({ title: '错误', msg: msg, buttons: Ext.Msg.OK, icon: (success) ? Ext.Msg.INFO : Ext.Msg.ERROR, modal: true });
    }
};

ext.net.comjs.deleteGridSelected = function (sender) {
    var delhint = App.DeleteHint.getValue();
    var grid = sender.up("grid");
    if (grid.hasSelection()) {
        Ext.Msg.confirm('提示', delhint, function (answer) {
            if (answer == "yes") {
                grid.deleteSelected();
            }
        });
    }
};

ext.net.comjs.onSubmitSuccess = function (response, data) {
    Ext.Msg.show({ title: '提示', msg: data.extraParams.Msg, buttons: Ext.Msg.OK, icon: Ext.Msg.INFO, modal: true,
        fn: function (btn) {
            var grid = window.parent.App.GridPanel1;
            if (grid != null) {
                grid.getStore().reload();
            }
            var wnd = window.parent.App.Window1;
            if (wnd != null) {
                wnd.close();
            }
        }
    });
};

ext.net.comjs.onSubmitFailure = function (response, data) {
    Ext.Msg.show({ title: '提示', msg: data.extraParams.Msg, buttons: Ext.Msg.OK, icon: Ext.Msg.ERROR, modal: true });
};

ext.net.comjs.onFormSubmit = function () {
    if (!App.FormPanel1.getForm().isValid()) {
        Ext.Msg.show({ title: '提示', icon: Ext.MessageBox.ERROR, msg: '表单信息未填写完整，请检查后再次提交！', buttons: Ext.Msg.OK }); 
        return false;
    }
}

ext.net.comjs.setFormStatusBar = function (btmbar, valid) {
    btmbar.dockedItems.get(1).setStatus({ text: valid ? '表单信息填写正确！' : '表单信息未填写完整，请检查后再次提交！', iconCls: valid ? 'icon-accept' : 'icon-exclamation' });
}